'use strict';
 
module.exports = app => {
    
    const { STRING, INTEGER } = app.Sequelize;
    const User = app.model.define('user',
        {
            id: { type: INTEGER, primaryKey: true, autoIncrement: true },
            username: STRING(255),
            password: STRING(255),
            status: INTEGER,
            avatar: STRING(255),
            nickname: STRING(255),
            phone: STRING(255),
            email: STRING(255),
            role_id:INTEGER
        },
        {
            freezeTableName: true, // Model 对应的表名将与model名相同
            timestamps: false
        }
    )
    User.associate = function() {
        app.model.User.belongsTo(app.model.Role, {foreignKey:'role_id', targetKey: 'id'});
    }

    User.allKeys = ['id', 'username', 'password', 'status', 'avatar', 'nickname', 'phone', 'email', 'role_id']

    return User;
};